package struts.utility;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import struts.base.BaseActionForm;

/**
 * 使用页面表单的数据填充javabean
 * @author Administrator
 *
 */
public class ViewFillFormData {
	public ViewFillFormData(){
		
	}
	
	public static BaseActionForm fill(String formpath,HttpServletRequest request){
		BaseActionForm form = null;
		try {
			Class clazz =Class.forName(formpath); //formBean.RegisterForm
			form=(BaseActionForm)clazz.newInstance();
			Field[] arr_field=clazz.getDeclaredFields();
			for(Field f:arr_field){
				f.setAccessible(true);
				f.set(form, request.getParameter(f.getName()));
				f.setAccessible(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return form;
	}
}
